package com.sixth.service.impl;

import com.sixth.annotation.PageInfoAdvice;
import com.sixth.bean.MarketFootprint;
import com.sixth.bean.MarketFootprintExample;
import com.sixth.bean.common.BasePageInfo;
import com.sixth.bean.vo.WxFootprintListVo;
import com.sixth.constant.Constant;
import com.sixth.mapper.MarketFootprintMapper;
import com.sixth.service.WxFootprintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @ClassName WxFootprintServiceImpl
 * @Description TODO
 * @Author XiaoWJ
 * @Date 2022/9/11 19:40
 **/
@Transactional
@Service
public class WxFootprintServiceImpl implements WxFootprintService {

    @Autowired
    MarketFootprintMapper marketFootprintMapper;


    @PageInfoAdvice
    @Override
    public Object list(BasePageInfo basePageInfo, Integer userId) {

        List<WxFootprintListVo> wxFootprintListVos = marketFootprintMapper.selectFootprintByUserId(userId);

        return wxFootprintListVos;
    }

    @Override
    public int delete(Integer id, Integer userId) {
        MarketFootprintExample example = new MarketFootprintExample();

        MarketFootprintExample.Criteria criteria = example.createCriteria();

        criteria.andIdEqualTo(id).andUserIdEqualTo(userId).andDeletedEqualTo(false);

        MarketFootprint marketFootprint = new MarketFootprint();

        marketFootprint.setDeleted(true);

        int affectRows = marketFootprintMapper.updateByExampleSelective(marketFootprint, example);

        return affectRows > 0 ? Constant.OK : Constant.NON;
    }
}
